package com.tddx.activiti.utils.springutils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContexHolder implements ApplicationContextAware {

	public static ApplicationContext ctx;
	
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		SpringContexHolder.ctx = applicationContext;
	}

	public static ApplicationContext getApplicationContext() {
		return ctx;
	}

	public <T> T getBean(Class<T> requiredType){
		return ctx.getBean(requiredType);
	}

	public Object getBean(String name){
		return ctx.getBean(name);
	}
	
	public <T> T getBean(String name, Class<T> requiredType){
		return ctx.getBean(name, requiredType); 
	}
	
}